var hold = 2400

Page({
  data: {
    screenWidth: 0,
    screenHeight: 0,
    device: 'TEST-0322'
  },

  onLoad: function(e) {
    this.setData({
      screenWidth: wx.getSystemInfoSync().windowWidth,
      screenHeight: wx.getSystemInfoSync().windowHeight,
    })
  },

  connect: function(e) {
    let tempDevice = null
    wx.showModal({
      content: '是否要连接设备',
      success: res => {
        if(res.confirm) {
          tempDevice = 'TEST-0322'
          this.setData({
            device: tempDevice
          })
        }
      }
    })


    this.setData({
      device: tempDevice
    })
  },

  disconnect: function(e) {
    wx.showModal({
      content: '是否要断开连接',
      success: res => {
        if(res.confirm) {
          this.setData({
            device: null
          })
        }
      }
    })
  },

  onShow: function(e) {
    wx.cloud.init()
    this.testCloud()
    console.log('onShow over')
  },

  testCloud: function(e) {
    wx.cloud.callFunction({
      name: 'autoFunc',
      success: res => {
        console.log('autoFunc return ', res.result)
      },
      fail: err => {
        console.log(err)
      }
    })
  }
})
